package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.yunnong.atvris.common.api.Page;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.common.dto.CommentDeleteParam;
import site.yunnong.atvris.common.dto.CommentQueryParam;
import site.yunnong.atvris.common.dto.CommentsParam;
import site.yunnong.atvris.common.exception.LocalAssert;
import site.yunnong.atvris.portal.service.CommentsService;
import site.yunnong.atvris.service.vo.CommentCardVO;

import javax.annotation.Resource;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-07日
 */
@Slf4j
@Api(tags = "评论管理")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentsService commentsService;

    @ApiOperation("添加评论")
    @PostMapping("/add")
    public ResultVO add(@RequestBody CommentsParam param) {
        int count = commentsService.addComment(param);
        LocalAssert.notZero(count, "添加评论失败");
        return new ResultVO().success();
    }

    @ApiOperation("删除评论")
    @PostMapping("/del")
    public ResultVO deleteVideoReview(@RequestBody CommentDeleteParam param) {
        int count = commentsService.delComment(param);
        LocalAssert.notZero(count, "无此评论");
        return new ResultVO().success();
    }

    // todo 回复暂不支持点赞、评论、删除等操作
    @ApiOperation("分页获取评论CardVO")
    @PostMapping("/list-with-reply")
    public ResultVO list(@RequestBody CommentQueryParam param) {
        Page<CommentCardVO> result = commentsService.listWithReply(param);
        return new ResultVO().success(result);
    }
}
